from coin.exchange.base.kr_rest.product import NativeProduct
from coin.exchange.pancakeswap_v2.kr_rest.constants import quote_currency_list
from coin.exchange.pancakeswap_v2.kr_rest.currency import PancakeswapCurrency


class PancakeswapProduct(NativeProduct):
  _exchange = "Pancakeswap"
  NativeCurrencyType = PancakeswapCurrency

  def __init__(self, base, quote):
    assert base != quote
    assert quote.currency in quote_currency_list, quote
    super().__init__(base, quote, "%s%s" % (base.native_currency, quote.native_currency))

  @classmethod
  def FromStrProductImpl(cls, product, current_datetime):
    assert type(product) == str, type(product)
    assert '-' in product, product
    pair = product.split('-')
    assert len(pair) == 2
    base, quote = pair
    return PancakeswapProduct.FromStrPair(base, quote, current_datetime)

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    assert type(product) == str
    return cls.FromStrProductImpl(product, current_datetime)
